//
// Created by 谢哲 on 2021/5/17.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

vector<int> vdata;
int n;

int find(int pos) {
    if (vdata[pos] == -1) return pos;
    return vdata[pos] = find(vdata[pos]);
}

void merge(int pos1, int pos2) {
    int p1 = find(pos1), p2 = find(pos2);
    if (p1!=p2) vdata[p1] = p2;
}

class Person {
public:
    int a, b, val;
    Person() = default;
    Person(int a, int b, int val): a(a), b(b), val(val) {}
};

int main() {
    int m;
    cin >> n >> m;
    vdata.resize(n+1, -1);

    vector<Person> person_data(m);
    for (int i=0; i<m; ++i) {
        cin >> person_data[i].a >> person_data[i].b >> person_data[i].val;
    }

    sort(person_data.begin(), person_data.end(), [](const Person& a, const Person& b) {
        return a.val > b.val;
    });

    map<int, int> map_data;

    for (const auto &p: person_data) {
        if (find(p.a) == find(p.b)) {
            cout << p.val;
            return 0;
        }
        if (map_data.find(p.a)==map_data.end()) {
            map_data[p.a] = p.b;
        }
        else {
            merge(map_data[p.a], p.b);
        }
        if (map_data.find(p.b)==map_data.end()) {
            map_data[p.b] = p.a;
        }
        else {
            merge(map_data[p.b], p.a);
        }
    }
    cout << 0;

    return 0;
}
